package com.sunday.factory.singletonDemo;

import java.util.concurrent.atomic.AtomicLong;

/**
 * @ClassName HungrySingleton
 * @Author JiangHai
 * @Date 2021/9/5 14:16
 **/
public class HungrySingleton {
    private AtomicLong id = new AtomicLong(0);
    private static HungrySingleton instance = new HungrySingleton();

    private HungrySingleton() {
        // 禁止通过反射创建对象
        if (instance != null) {
            throw new IllegalArgumentException();
        }
    }

    public static HungrySingleton getInstance() {
        return instance;
    }

    public long getId() {
        return id.incrementAndGet();
    }
}
